package com.genius.reservation.reservation.service.impl;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.genius.reservation.UseTime.entity.UseTimeEntity;
import com.genius.reservation.UseTime.service.IUseTimeService;
import com.genius.reservation.car.entity.ReservationStartCarInformation;
import com.genius.reservation.common.ResponseRule;
import com.genius.reservation.common.constant.Constant;
import com.genius.reservation.common.constant.ResStatusCode;
import com.genius.reservation.common.rabbitmq.RabbitMessageEntity;
import com.genius.reservation.common.rabbitmq.RabbitService;
import com.genius.reservation.inspect.entity.ReservationToInspect;
import com.genius.reservation.mapper.*;
import com.genius.reservation.order.entity.OrderInformation;
import com.genius.reservation.platform.entity.PlatformInformation;
import com.genius.reservation.platform.service.IPlatformService;
import com.genius.reservation.receiver.entity.ReceiverInformation;
import com.genius.reservation.receiver.service.IReceiverInformationService;
import com.genius.reservation.reservation.entity.ReservationInformation;
import com.genius.reservation.reservation.entity.ReservationOrderInformation;
import com.genius.reservation.reservation.service.IReservationInformationService;
import com.genius.reservation.tools.QRcodeTools;
import com.genius.reservation.tools.SendWXMsg;
import com.genius.reservation.tools.annotation.webLog;
import com.genius.reservation.user.service.IUserInformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * <p>
 * 预约信息 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2022-05-26
 */
@Service
public class ReservationInformationServiceImpl extends ServiceImpl<ReservationInformationMapper, ReservationInformation> implements IReservationInformationService {


    private List<ReceiverInformation> receiverList = new ArrayList<>();
    //    @Autowired
//    RabbitTemplate rabbitTemplate;
    @Autowired
    ReservationInformationMapper reservationInformationMapper;

    @Autowired
    IPlatformService platformService;

    @Autowired
    RabbitService rabbitService;

    @Autowired
    @Lazy
    IReceiverInformationService receiverService;
    @Autowired
    IUseTimeService useTimeService;

    @Autowired
    @Lazy
    DriverInformationMapper driverMapper;

    @Autowired
    @Lazy
    IUserInformationService userService;

    @Autowired
    SendWXMsg sendWXMsg;

    @Autowired
    @Lazy
    ReservationToInspectMapper reservationToInspectMapper;

    @Autowired
    @Lazy
    OrderInformationMapper orderMapper;

    @Autowired
    @Lazy
    ReservationOrderInformationMapper reservationOrderMapper;

    @Autowired
    @Lazy
    ReservationStartCarInformationMapper reservationStartCarMapper;

    @Autowired
    @Lazy
    SupplierOrderInformationMapper supplierOrderMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    //生成二维码预约单
    public ResponseRule createReservation(String orderNumber, String supplierNumber, String supplierName) {
        synchronized (this) {
            if (ObjectUtil.isEmpty(supplierNumber))
                return ResponseRule.no("创建预约单失败,信息填写有误");
            if (Objects.equals(orderNumber, "") || orderNumber == null) {
                return ResponseRule.no("创建预约单失败,信息填写有误");
            }
            //创建预约单
            ReservationInformation reservationInformation = new ReservationInformation();
            reservationInformation.setReservationNumber(Constant.RESERVATION_PREFIX + DateTime.now().toString().replace("-", "").replace(":", "").replace(" ", ""));
            reservationInformation.setNowStatus(ResStatusCode.RESERVATION_LAUNCH);
            reservationInformation.setSupplierNumber(supplierNumber);
            reservationInformation.setSupplierName(supplierName);
            Map<String, Object> unReservationOrder = this.getUnReservationOrder(orderNumber);
            reservationInformation.setGdsNumber((Integer) unReservationOrder.get("itemNum"));
            reservationInformation.setGdsCount((Integer) unReservationOrder.get("number"));
            reservationInformation.setReservationName(supplierName);
            //缺少插入二维码
            ReservationInformation re = this.addAndUp(reservationInformation);


            //创建订单记录表
            ReservationOrderInformation reservationOrderInformation = new ReservationOrderInformation();
            reservationOrderInformation.setReservationNumber(re.getReservationNumber());
            reservationOrderInformation.setOrderNumber(orderNumber);
            reservationOrderInformation.setSupplierNumber(supplierNumber);
            reservationOrderInformation.setSupplierName(supplierName);
            reservationOrderInformation.setGdsCount((Integer) unReservationOrder.get("itemNum"));
            reservationOrderInformation.setGdsNumber((Integer) unReservationOrder.get("number"));
            reservationOrderInformation.setRecordDate((String) unReservationOrder.get("recordDate"));
            reservationOrderInformation.setEndDate((String) unReservationOrder.get("endDate"));
            reservationOrderMapper.save(reservationOrderInformation);
            String qRcode = QRcodeTools.createQRcode("jhshyy.jinhubianli.com/unite_platform/supplierPage/?r=" + re.getReservationNumber());
            reservationInformation.setQRCode(qRcode);

            try {
                RabbitMessageEntity<ReservationInformation> obj = new RabbitMessageEntity<>();
                obj.setData(re);
                obj.setMsg(String.format("收到了新的预约,单号为:%s", re.getReservationNumber()));
                obj.setReservationNumber(re.getReservationNumber());
                rabbitService.ToReceiverManager(obj);
                String wxNumber = userService.getUserByUserNumber(re.getSupplierNumber()).getWxNumber();
                sendWXMsg.sendMsg(wxNumber, "预约申请已提交");
                return ResponseRule.ok(re, "预约申请提交成功,请等待审核");
            } catch (Exception e) {
                e.getStackTrace();
                throw new RuntimeException();
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule submitReservation(String reservationNumber,
                                          String itemNum,
                                          String number,
                                          String month,
                                          String time,
                                          String cars,
                                          String[] orderNumbers,
                                          String supplierName,
                                          String supplierNumber,
                                          String reservationName) {
        //预约单
        ReservationInformation byReservationNumber;
        //二维码
        ArrayList<Object> qrCodes = new ArrayList<>();

        byReservationNumber = this.getByReservationNumber(reservationNumber);


        if (ObjectUtil.isEmpty(byReservationNumber)) {
            byReservationNumber = new ReservationInformation();
            byReservationNumber.setReservationNumber(Constant.RESERVATION_PREFIX + DateTime.now().toString().replace("-", "").replace(":", "").replace(" ", ""));
            byReservationNumber.setSupplierNumber(supplierNumber);
            byReservationNumber.setSupplierName(supplierName);
            byReservationNumber.setReservationName(reservationName);
        }

        byReservationNumber.setGdsNumber(Integer.valueOf(number));
        byReservationNumber.setGdsCount(Integer.valueOf(itemNum));

        byReservationNumber.setEstimatedArrivalTime(month + " " + time);

        //司机
        JSONObject objects = JSONObject.parseObject(cars);
        StringBuilder qRcode = new StringBuilder();
        for (int i = 0; i < objects.size(); i++) {
            JSONObject jsonObject = objects.getJSONObject("carData" + i);
            /*
            *   carCode:'',
                carType:'',
                carLength:''
             * */
            String carCode = "";
            if (ObjectUtil.isNotEmpty(jsonObject.getString("carCode"))) {
                carCode = jsonObject.getString("carCode");
            }
            System.out.println(jsonObject);
            System.out.println(carCode);
            String carType = jsonObject.getString("carType");
            String carLength = jsonObject.getString("carLength");
            ReservationStartCarInformation reservationStartCarInformation = new ReservationStartCarInformation();
            reservationStartCarInformation.setReservationNumber(byReservationNumber.getReservationNumber());
            reservationStartCarInformation.setSupplierName(supplierName);
            reservationStartCarInformation.setCarCode(carCode);
            reservationStartCarInformation.setCarType(carType);
            reservationStartCarInformation.setCarLength(carLength);
            reservationStartCarInformation.setNowStatus(ResStatusCode.RESERVATION_CONFIRM);
            reservationStartCarInformation.setConfirmArriveTime(DateTime.now().toString());
            ReservationStartCarInformation ad = reservationStartCarMapper.ad(reservationStartCarInformation);
            String qr=QRcodeTools.createQRcode("https://jhshyy.jinhubianli.com/unite_platform/driverPage/?s=" + ad.getId() + "&r=" + byReservationNumber.getReservationNumber());
            reservationStartCarInformation.setQrCode(qr);
            reservationStartCarMapper.up(reservationStartCarInformation);
            qRcode.append(qr).append("卍");
            HashMap<String, Object> qrCodeData = new HashMap<>();
            qrCodeData.put("carData",ad);
            qrCodes.add(qrCodeData);
        }
        qRcode = new StringBuilder(StrUtil.sub(qRcode, 0, qRcode.length() - 1));
        //更新一个二维码 状态切到司机上报信息页面
        byReservationNumber.setQRCode(qRcode.toString());

        //订单
        for (String orderNumber : orderNumbers) {
            ReservationOrderInformation reservationOrderInformation = new ReservationOrderInformation();
            reservationOrderInformation.setSupplierName(byReservationNumber.getSupplierName());
            reservationOrderInformation.setSupplierNumber(byReservationNumber.getSupplierNumber());
            reservationOrderInformation.setOrderNumber(orderNumber);
            reservationOrderInformation.setGdsNumber(Integer.valueOf(number));
            reservationOrderInformation.setGdsCount(Integer.valueOf(itemNum));
            reservationOrderInformation.setReservationNumber(byReservationNumber.getReservationNumber());
            reservationOrderMapper.ad(reservationOrderInformation);
        }
        byReservationNumber.setNowStatus(ResStatusCode.RESERVATION_WAIT_CONFIRM);
        ReservationInformation reservationInformation = this.addAndUp(byReservationNumber);
        ReservationToInspect reservationToInspect = new ReservationToInspect();
        reservationToInspect.setInspectTypeNumber("1");
        reservationToInspect.setReservationNumber(reservationInformation.getReservationNumber());
        reservationToInspectMapper.save(reservationToInspect);
        RabbitMessageEntity<Object> obj = new RabbitMessageEntity<>();
        obj.setData(reservationInformation);
        obj.setMsg(String.format("收到了新预约,单号为:%s", reservationInformation.getReservationNumber()));
        obj.setReservationNumber(reservationInformation.getReservationNumber());
        rabbitService.ToReceiverManager(obj);
        String wxNumber = userService.getUserByUserNumber(reservationInformation.getSupplierNumber()).getWxNumber();
//        sendWXMsg.sendMsg(wxNumber, "预约申请已提交");
//        HashMap<String, Object> resultData = new HashMap<>();
//        resultData.put("reservation",reservationInformation);
//        resultData.put("qrCodes",qrCodes);
//        return ResponseRule.ok(resultData, "预约申请已提交,等待审核");

        Integer data = (Integer) getBoxamount(byReservationNumber.getReservationNumber()).getData();
        confirmReservation(byReservationNumber.getReservationNumber(),byReservationNumber.getEstimatedArrivalTime(),byReservationNumber.getEstimatedArrivalTime(),data,)
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule confirmReservation(String reservationNumber, String confirmArrivalTime, String confirmOverTime, Integer trayCount, List<JSONObject> cars) {


        synchronized (this) {
            ReservationInformation reservation = this.getByReservationNumber(reservationNumber);
            if (reservation.getNowStatus() != ResStatusCode.RESERVATION_WAIT_CONFIRM || reservation.getNowStatus() == ResStatusCode.RESERVATION_CONFIRM)
                return ResponseRule.no("订单确认失败,状态异常");


            reservation.setConfirmArrivalTime(confirmArrivalTime);
            reservation.setNowStatus(ResStatusCode.RESERVATION_CONFIRM);
            reservation.setTrayCount(trayCount);
            reservation.setConfirmOverTime(confirmOverTime);

            for (JSONObject car : cars) {

                //添加预约时间记录
                UseTimeEntity useTimeEntity = new UseTimeEntity();
                DateTime parse = DateUtil.parse(reservation.getConfirmArrivalTime());
                useTimeEntity.setReceiverNumber(car.getString("receiver"));
                useTimeEntity.setPlatformNumber(car.getString("platform"));
                useTimeEntity.setStartTime(reservation.getConfirmArrivalTime());
                useTimeEntity.setOverTime(parse.offset(DateField.MINUTE, Integer.parseInt(reservation.getConfirmOverTime())).toString());
                useTimeEntity.setStartHour(String.valueOf(parse.hour(true)));
                useTimeEntity.setStartYear(String.valueOf(parse.year()));
                useTimeEntity.setStartMonth(String.valueOf(parse.month() + 1));
                useTimeEntity.setStartDay(String.valueOf(parse.dayOfMonth()));
                useTimeEntity.setStartMinute(String.valueOf(parse.minute()));

                //更新车辆信息
                String id = car.getString("carId");
                ReservationStartCarInformation carInformation = reservationStartCarMapper.selectById(id);
                if (ObjectUtil.isEmpty(carInformation)) {
                    return ResponseRule.no("未找到车辆信息");
                }
                carInformation.setConfirmPlatformNumber(car.getString("platform"));
                carInformation.setConfirmReceiverNumber(car.getString("receiver"));
                System.out.println(car.getString("receiver"));
                String phonee = userService.getUserByUserNumber(car.getString("receiver")).getPhone();
                carInformation.setActualPlatformNumber(car.getString("platform"));
                carInformation.setReceiverPhone(phonee);
                carInformation.setActualReceiverNumber(car.getString("receiver"));
                carInformation.setActualArrivalTime(confirmArrivalTime);
                carInformation.setNowStatus(ResStatusCode.RESERVATION_CONFIRM);
                UseTimeEntity useTimeEntity1 = useTimeService.addAndUp(useTimeEntity);
                carInformation.setUseTimeId(useTimeEntity1.getId());
                ReservationStartCarInformation up = reservationStartCarMapper.up(carInformation);
                String receiverNumber = up.getActualReceiverNumber();
                String receWxNumber = userService.getUserByUserNumber(receiverNumber).getWxNumber();
                String receiver = userService.getUserByUserNumber(car.getString("receiver")).getWxNumber();
                sendWXMsg.sendSuccessMsg(receiver,  reservation.getReservationNumber());
                sendWXMsg.sendMsg(receWxNumber,  "收到收货任务,单号:"+reservation.getReservationNumber());
            }

            ReservationInformation re = this.addAndUp(reservation);
            RabbitMessageEntity<Object> objectRabbitMessageEntity = new RabbitMessageEntity<>();
            objectRabbitMessageEntity.setData(reservation);
            objectRabbitMessageEntity.setMsg("预约单已确认");
            objectRabbitMessageEntity.setReservationNumber(reservationNumber);
            String supplierWxNumber = userService.getUserByUserNumber(re.getSupplierNumber()).getWxNumber();
            sendWXMsg.sendSuccessMsg(supplierWxNumber,  reservation.getReservationNumber());
            return ResponseRule.ok(re, "预约单确认成功");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReservationInformation actualArrivalTime(ReservationInformation reservation) {
        synchronized (this) {
            reservation.setNowStatus(ResStatusCode.RESERVATION_ARRIVE);
            return this.addAndUp(reservation);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReservationInformation actualPlatformTime(ReservationInformation reservation) {
        synchronized (this) {
            reservation.setNowStatus(ResStatusCode.RESERVATION_ARRIVE);
            return this.addAndUp(reservation);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReservationInformation actualReceiver(ReservationInformation reservation) {
        synchronized (this) {
            reservation.setNowStatus(ResStatusCode.RESERVATION_ARRIVE);
            return this.addAndUp(reservation);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule cancelReceiver(String reservationNumber) {
        LambdaQueryWrapper<ReservationStartCarInformation> eq1 = new LambdaQueryWrapper<ReservationStartCarInformation>().eq(ReservationStartCarInformation::getReservationNumber, reservationNumber);
        List<ReservationStartCarInformation> reservationStartCarInformations = reservationStartCarMapper.selectList(eq1);
        synchronized (this) {
            for (ReservationStartCarInformation reservationStartCarInformation : reservationStartCarInformations) {
                if(reservationStartCarInformation.getNowStatus()==ResStatusCode.RESERVATION_SETOUT) return ResponseRule.no("已有车辆发车,无法取消预约");
                useTimeService.removeById(reservationStartCarInformation.getUseTimeId());
                reservationStartCarInformation.setNowStatus(ResStatusCode.RESERVATION_CANCEL);
            }
            ReservationInformation re = this.getByReservationNumber(reservationNumber);
            re.setNowStatus(ResStatusCode.RESERVATION_CANCEL);
            ReservationInformation reservationInformation = this.addAndUp(re);
            LambdaQueryWrapper<OrderInformation> eq = orderMapper.getWrapper().eq(OrderInformation::getReservationNumber, reservationNumber);
            List<OrderInformation> orderInformations = orderMapper.selectList(eq);
            if (ArrayUtil.isEmpty(orderInformations)) {
                ResponseRule.no("没有找到订单");
            }
            for (OrderInformation orderInformation : orderInformations) {
                orderMapper.deleteById(orderInformation.getId());
            }
            if (re.getDrivers().size() == 0) {
                RabbitMessageEntity<Object> obj = new RabbitMessageEntity<>();
                obj.setData(re);
                obj.setMsg(String.format("预约被取消了请及时查看,单号为:%s", reservationNumber));
                obj.setReservationNumber(reservationNumber);
                rabbitService.ToReceiverManager(obj);
                rabbitService.ToSupplier(obj);
                rabbitService.ToDriver(obj);
                rabbitService.ToReceiver(obj);
                String supplierWxNumber = userService.getUserByUserNumber(reservationInformation.getSupplierNumber()).getWxNumber();
                sendWXMsg.sendCancelMsg(supplierWxNumber, "单号:"+re.getReservationNumber()+"时间错误,取消预约");
            } else {
                for (ReservationStartCarInformation driver : re.getDrivers()) {
                    if (!(Objects.equals(driver.getConfirmReceiverNumber(), "-1"))) {
                        String receWxNumber = userService.getUserByUserNumber(driver.getActualReceiverNumber()).getWxNumber();
                        sendWXMsg.sendCancelMsg(receWxNumber, "单号:"+re.getReservationNumber()+"预约被取消");
                    }
                }
            }
            return ResponseRule.ok("预约取消成功");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule editReservation(ReservationInformation reservation) {
        synchronized (this) {
            LambdaQueryWrapper<ReservationInformation> eq = this.getBaseMapper().getQueryWrapper().eq(ReservationInformation::getReservationNumber, reservation.getReservationNumber());
            ReservationInformation re = this.getOne(eq);
            re.setEstimatedArrivalTime(reservation.getEstimatedArrivalTime());
//            re.setOrderNumber(reservation.getOrderNumber());
            ReservationInformation reservationInformation = this.addAndUp(re);
            RabbitMessageEntity<Object> obj = new RabbitMessageEntity<>();
            obj.setData(re);
            obj.setMsg(String.format("预约被修改了请及时查看,单号为:%s", reservationInformation.getReservationNumber()));
            obj.setReservationNumber(reservationInformation.getReservationNumber());
            rabbitService.ToReceiverManager(obj);
            return ResponseRule.ok("预约修改成功");
        }
    }

    @Override
    public JSONObject getAllReservation(int page,int limit) {
        List<ReservationInformation> allReservation = reservationInformationMapper.getAllReservation();
        int nPage = page-1;  // 0   1
        int nLimit = limit -1; // 14  14

        int wOver = page * limit - 1>=allReservation.size()-1?
                allReservation.size()-1:
                page * limit - 1;// 14   29
        int wStart = nPage * limit;//0  15

        List<ReservationInformation> n = new ArrayList<>();
        for(int i = wStart;i<=wOver;i++){
            n.add(allReservation.get(i));
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","ok");
        jsonObject.put("data",n);
        jsonObject.put("count",allReservation.size());
        return jsonObject;
    }


    //司机完成预约
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule finishReservationSupplier(String reservationNumber) {
        synchronized (this) {
            LambdaQueryWrapper<ReservationInformation> eq = this.getBaseMapper().getQueryWrapper().eq(ReservationInformation::getReservationNumber, reservationNumber);
            ReservationInformation re = this.getOne(eq);
            RabbitMessageEntity<Object> obj = new RabbitMessageEntity<>();
            obj.setData(re);
            obj.setMsg(String.format("预约已完成请处理,单号为:%s", reservationNumber));
            obj.setReservationNumber(reservationNumber);
            rabbitService.ToReceiverManager(obj);
            rabbitService.ToSupplier(obj);
            return ResponseRule.ok("预约已完成");
        }
    }

    //收获主管完成预约
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseRule finishReservationReceiver(String reservationNumber) {
        synchronized (this) {
            LambdaQueryWrapper<ReservationInformation> eq = this.getBaseMapper().getQueryWrapper().eq(ReservationInformation::getReservationNumber, reservationNumber);
            ReservationInformation re = this.getOne(eq);
            re.setNowStatus(ResStatusCode.RESERVATION_FINISH);
            RabbitMessageEntity<Object> obj = new RabbitMessageEntity<>();
            obj.setData(re);
            obj.setMsg("已确认预约完成");
            obj.setReservationNumber(reservationNumber);
            rabbitService.ToDriver(obj);
            rabbitService.ToSupplier(obj);
//            System.out.println("11111111111111111111111111");
            return ResponseRule.ok("预约已完成");
        }
    }

    //    @Override
//    public ReservationInformation getByReservationNumber(String reservationNumber) {
//        LambdaQueryWrapper<ReservationInformation> eq = this.getBaseMapper().getQueryWrapper().eq(ReservationInformation::getReservationNumber, reservationNumber);
//        return this.getOne(eq);
//    }
    @Override
    public ReservationInformation getByReservationNumber(String reservationNumber) {
        return reservationInformationMapper.selectOneById(reservationNumber);
    }

    @Override
    public ResponseRule findFreePlatform() {
        List<PlatformInformation> freePlatform = platformService.findFreePlatform();
        return ResponseRule.ok(freePlatform);
    }

    @Override
    public ResponseRule findFreeReceiver() {
        List<ReceiverInformation> re = receiverService.getBaseMapper().selectList(new LambdaQueryWrapper<ReceiverInformation>()
                .eq(ReceiverInformation::getIsFree, 0).eq(ReceiverInformation::getIsFree,0));
        return ResponseRule.ok(re);
    }

    @Override
    public ResponseRule findReservationBySupplier(String supplierNumber) {
        List<ReservationInformation> reservationInformations = reservationInformationMapper.selectOneBySupplier(supplierNumber);
        return ResponseRule.ok(reservationInformations);
    }

    @Override
    public ResponseRule findReservationBySupplierFive(String supplierNumber) {
        List<ReservationInformation> allReservationFive = reservationInformationMapper.getAllReservationFiveBySupplier(supplierNumber);
        return ResponseRule.ok(allReservationFive);
    }

    @Override
    public ResponseRule findReservationByDriver(String driverNumber) {
        List<ReservationInformation> reservationInformations = reservationInformationMapper.selectOneByDriver(driverNumber);
        return ResponseRule.ok(reservationInformations);
    }

    @Override
    public List<ReservationInformation> findReservationByDriverList(String driverNumber) {
        return reservationInformationMapper.selectOneByDriver(driverNumber);
    }

    @Override
    public ResponseRule findReservationByDriverFive(String driverNumber) {
        List<ReservationInformation> allReservationFiveByDriver = reservationInformationMapper.getAllReservationFiveByDriver(driverNumber);
        return ResponseRule.ok(allReservationFiveByDriver);
    }

    @Override
    public ResponseRule findReservationByReceiver(String receiverNumber) {
        List<ReservationInformation> reservationInformations = reservationInformationMapper.selectOneByReceiver(receiverNumber);
        return ResponseRule.ok(reservationInformations);
    }

    @Override
    public ResponseRule findReservationByReceiverFive(String receiverNumber) {
        List<ReservationInformation> allReservationFiveByReceiver = reservationInformationMapper.getAllReservationFiveByReceiver(receiverNumber);
        return ResponseRule.ok(allReservationFiveByReceiver);
    }

    @Override
    public ResponseRule findReservation(String reservationNumber) {
        ReservationInformation reservationInformation = reservationInformationMapper.selectOneById(reservationNumber);
        return ResponseRule.ok(reservationInformation);
    }

    @Override
    public ResponseRule getIncompleteReservationByReceiver(String receiverNumber) {
        List<ReservationInformation> incompleteReservationByReceiver = reservationInformationMapper.getIncompleteReservationByReceiver(receiverNumber);
        for (ReservationInformation reservationInformation : incompleteReservationByReceiver) {
            LambdaQueryWrapper<ReservationStartCarInformation> eq = reservationStartCarMapper.getWrapper().eq(ReservationStartCarInformation::getReservationNumber, reservationInformation.getReservationNumber());
            List<ReservationStartCarInformation> reservationStartCarInformations = reservationStartCarMapper.selectList(eq);
            if (ArrayUtil.isEmpty(reservationStartCarInformations)) {
                reservationInformation.setDrivers(null);
            } else {
                reservationInformation.setDrivers(reservationStartCarInformations);
            }
            //修改startcar数据库的表字段，因为现在多个月台对应多个车辆
        }
        return ResponseRule.ok(incompleteReservationByReceiver);
    }

    @Override
    public ResponseRule getIncompleteReservationByReceiverByStartCar(String receiverNumber) {
        List<ReservationStartCarInformation> listByActualReceiverNumber = reservationStartCarMapper.getUnfinishByStartCarId(receiverNumber);
        if (ArrayUtil.isEmpty(listByActualReceiverNumber)) {
            return ResponseRule.no("未找到预约单信息");
        }
        return ResponseRule.ok(listByActualReceiverNumber);

    }

    @Override
    public ResponseRule getFinishReservationByReceiverByStartCar(String receiverNumber) {
        List<ReservationStartCarInformation> listByActualReceiverNumber = reservationStartCarMapper.getListByActualReceiverNumber(receiverNumber);
        if (ArrayUtil.isEmpty(listByActualReceiverNumber)) {
            return ResponseRule.no("未找到预约单信息");
        }
        return ResponseRule.ok(listByActualReceiverNumber);
    }

    @Override
    public ResponseRule getUncompletedReservation() {
        List<ReservationInformation> uncompleteReservation = reservationInformationMapper.getUncompleteReservation();
        return ResponseRule.ok(uncompleteReservation);
    }

    @Override
    public ResponseRule getCompleteReservation() {
        List<ReservationInformation> completeReservation = reservationInformationMapper.getCompleteReservation();
        return ResponseRule.ok(completeReservation);
    }

    @Override
    public ResponseRule getLateReservation() {
        List<ReservationInformation> lateReservationByReceiver = reservationInformationMapper.getLateReservationByReceiver();
        return ResponseRule.ok(lateReservationByReceiver);
    }

    @Override
    public ResponseRule getUnlateReservation() {
        List<ReservationInformation> unlateReservationByReceiver = reservationInformationMapper.getUnlateReservationByReceiver();
        return ResponseRule.ok(unlateReservationByReceiver);
    }

    //查看当前时间所有被使用的月台
    @Override
    public ResponseRule checkUsedTime(String year, String month, String day, String hour) {
        LambdaQueryWrapper<UseTimeEntity> eq = useTimeService.getWrapper()
                .eq(UseTimeEntity::getStartYear, year)
                .eq(UseTimeEntity::getStartMonth, month)
                .eq(UseTimeEntity::getStartDay, day)
                .eq(UseTimeEntity::getStartHour, hour);
//                .eq(UseTimeEntity::getType, 0);
        List<UseTimeEntity> list = useTimeService.list(eq);
        if (list.isEmpty())
            return ResponseRule.no("没有找到");
        return ResponseRule.ok(list);
    }

    @Override
    //查看当前时间所有被使用的收货员
    public ResponseRule checkUsedReceiver(String year, String month, String day, String hour) {
        LambdaQueryWrapper<UseTimeEntity> eq = useTimeService.getWrapper()
                .eq(UseTimeEntity::getStartYear, year)
                .eq(UseTimeEntity::getStartMonth, month)
                .eq(UseTimeEntity::getStartDay, day)
                .eq(UseTimeEntity::getStartHour, hour);
//                .eq(UseTimeEntity::getType, 1);
        List<UseTimeEntity> list = useTimeService.list(eq);
        if (list.isEmpty())
            return ResponseRule.no("没有找到");
        return ResponseRule.ok(list);
    }


    //检查当前时间当前月台是否可用
    @Override
    public ResponseRule checkTimeIsUse(String startTime, String overTime, String platformNumber) {
        DateTime start = DateUtil.parse(startTime);
        DateTime over = DateUtil.parse(overTime);
        //取到当前小时内的所有预约
        LambdaQueryWrapper<UseTimeEntity> eq = useTimeService.getWrapper()
                .eq(UseTimeEntity::getStartYear, "" + start.year())
                .eq(UseTimeEntity::getStartMonth, "" + start.month())
                .eq(UseTimeEntity::getStartDay, "" + start.dayOfMonth())
                .eq(UseTimeEntity::getStartHour, "" + start.hour(true))
//                .eq(UseTimeEntity::getType, 1)
                .eq(UseTimeEntity::getPlatformNumber, platformNumber);
        List<UseTimeEntity> list = useTimeService.list(eq);
        for (UseTimeEntity useTimeEntity : list) {
            DateTime parse = DateUtil.parse(useTimeEntity.getStartTime());
            DateTime parse1 = DateUtil.parse(useTimeEntity.getOverTime());
            //预约时间被占用
            if (parse.before(start) || parse1.after(over)) {
                return ResponseRule.no(useTimeEntity, "该月台当前时间已被预约,请更换其他月台或时间");
            }
        }
        return ResponseRule.ok();
    }


    //检查当前时间当前收货员是否可用
    @Override
    public ResponseRule checkReceiverIsUse(String startTime, String overTime, String receiverNumber) {
        DateTime start = DateUtil.parse(startTime);
        DateTime over = DateUtil.parse(overTime);
        //取到当前小时内的所有预约
        LambdaQueryWrapper<UseTimeEntity> eq = useTimeService.getWrapper()
                .eq(UseTimeEntity::getStartYear, "" + start.year())
                .eq(UseTimeEntity::getStartMonth, "" + start.month())
                .eq(UseTimeEntity::getStartDay, "" + start.dayOfMonth())
                .eq(UseTimeEntity::getStartHour, "" + start.hour(true))
//                .eq(UseTimeEntity::getType, 0)
                .eq(UseTimeEntity::getReceiverNumber, receiverNumber);
        List<UseTimeEntity> list = useTimeService.list(eq);
        for (UseTimeEntity useTimeEntity : list) {
            DateTime parse = DateUtil.parse(useTimeEntity.getStartTime());
            DateTime parse1 = DateUtil.parse(useTimeEntity.getOverTime());
            //预约时间被占用
            if (parse.before(start) || parse1.after(over)) {
                return ResponseRule.no(useTimeEntity, "该收货员当前时间已被预约,请更换其他收货员或时间");
            }
        }
        return ResponseRule.ok();
    }

    //下拉列表可用月台
    @Override
    public ResponseRule freePlatformByTime(String startTime, Integer keepTime) {
        //加载所有月台
        List<PlatformInformation> Platforms = platformService.list();


        DateTime start = DateUtil.parse(startTime);
        DateTime over = start.offsetNew(DateField.MINUTE, keepTime);

        //取到当前小时内的所有预约  过滤到小时
        LambdaQueryWrapper<UseTimeEntity> eq = useTimeService.getWrapper()
                .eq(UseTimeEntity::getStartYear, "" + start.year())
                .eq(UseTimeEntity::getStartMonth, "" + (start.month() + 1))
                .eq(UseTimeEntity::getStartDay, "" + start.dayOfMonth());
//                .eq(UseTimeEntity::getStartHour, "" + (start.hour(true)));


        //当前小时内的所有预约单
        List<UseTimeEntity> list = useTimeService.list(eq);


        //循环判断
        assert Platforms != null;
        //循环所有预约
        for (UseTimeEntity useTimeEntity : list) {
            DateTime kaishi = DateUtil.parse(useTimeEntity.getStartTime());
            DateTime jieshu = DateUtil.parse(useTimeEntity.getOverTime());



//            if (start.after(kaishi) || start.before(jieshu) || over.after(kaishi) || over.before(jieshu)) {
            if ((start.isAfterOrEquals(kaishi) && over.isBeforeOrEquals(jieshu)) || (over.isAfterOrEquals(kaishi)&&over.isBeforeOrEquals(jieshu) )|| start.isBeforeOrEquals(jieshu)&&start.isAfterOrEquals(kaishi)) {
                for (PlatformInformation platform : Platforms) {
                    if (Objects.equals(platform.getPlatformNumber(), useTimeEntity.getPlatformNumber())) {
                        platform.setSure(0);
                    }
                }
            }
        }
        return ResponseRule.ok(Platforms);
    }


    @Override
    public ResponseRule freeReceiverByTime(String startTime, Integer keepTime) {

        LambdaQueryWrapper<ReceiverInformation> ne = new LambdaQueryWrapper<ReceiverInformation>().eq(ReceiverInformation::getDutyFlag, 0);

        //加载所有月台
        List<ReceiverInformation> receivers = receiverService.list(ne);


        DateTime start = DateUtil.parse(startTime);
        DateTime over = start.offsetNew(DateField.MINUTE, keepTime);


        //取到当前小时内的所有预约  过滤到小时
        LambdaQueryWrapper<UseTimeEntity> eq = useTimeService.getWrapper()
                .eq(UseTimeEntity::getStartYear, "" + start.year())
                .eq(UseTimeEntity::getStartMonth, "" + (start.month() + 1))
                .eq(UseTimeEntity::getStartDay, "" + start.dayOfMonth());


        //当前小时内的所有预约单
        List<UseTimeEntity> list = useTimeService.list(eq);
        //循环判断
        assert receivers != null;
        //循环所有预约
        for (UseTimeEntity useTimeEntity : list) {
            DateTime kaishi = DateUtil.parse(useTimeEntity.getStartTime());
            DateTime jieshu = DateUtil.parse(useTimeEntity.getOverTime());

            if ((start.isAfterOrEquals(kaishi) && over.isBeforeOrEquals(jieshu)) ||
                    (over.isAfterOrEquals(kaishi)&&over.isBeforeOrEquals(jieshu) )||
                    start.isBeforeOrEquals(jieshu)&&start.isAfterOrEquals(kaishi)) {
                //被占用
                for (ReceiverInformation receiver : receivers) {
                    if (Objects.equals(receiver.getReceiverNumber(), useTimeEntity.getReceiverNumber())) receiver.setSure(0);
                }
            }
        }
        return ResponseRule.ok(receivers);
    }

    @Override
    public JSONObject searchTable(String key, String value,int page,int limit) {
        List<ReservationInformation> reservationInformations = reservationInformationMapper.searchTable(key, value);
        int nPage = page-1;  // 0   1
        int nLimit = limit -1; // 14  14


        int wOver = page * limit - 1>=reservationInformations.size()-1?
                reservationInformations.size()-1:
                page * limit - 1;// 14   29
        int wStart = nPage * limit;//0  15

        List<ReservationInformation> n = new ArrayList<>();
        for(int i = wStart;i<=wOver;i++){
            n.add(reservationInformations.get(i));
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","ok");
        jsonObject.put("data",n);
        jsonObject.put("count",reservationInformations.size());
        return jsonObject;
    }

    @Override
    public ResponseRule getReservationByOrder(String orderNumber) {
        System.out.println(orderNumber);
        List<ReservationInformation> oneByOrder = reservationInformationMapper.getOneByOrder(orderNumber);
        if (oneByOrder.size() != 0) {
            for (ReservationInformation reservationInformation : oneByOrder) {
                if (reservationInformation.getNowStatus() == ResStatusCode.RESERVATION_FINISH
                        && reservationInformation.getNowStatus() != ResStatusCode.RESERVATION_CANCEL)
                    return ResponseRule.no();
            }
        }
        return ResponseRule.ok();
    }

    @Override
    public ResponseRule getAllFreeReceiverByTime(String startTime, Integer keepTime) {
        //加载所有空闲收货员
        LambdaQueryWrapper<ReceiverInformation> eq1 = receiverService.getWrapper().eq(ReceiverInformation::getIsFree, 1);
        List<ReceiverInformation> receivers = receiverService.list(eq1);


        DateTime start = DateUtil.parse(startTime);
        DateTime over = start.offsetNew(DateField.MINUTE, keepTime);


        //取到当前小时内的所有预约  过滤到小时
        LambdaQueryWrapper<UseTimeEntity> eq = useTimeService.getWrapper()
                .eq(UseTimeEntity::getStartYear, "" + start.year())
                .eq(UseTimeEntity::getStartMonth, "" + (start.month() + 1))
                .eq(UseTimeEntity::getStartDay, "" + start.dayOfMonth());
//                .eq(UseTimeEntity::getStartHour, "" + (start.hour(true)));


        //当前小时内的所有预约单
        List<UseTimeEntity> list = useTimeService.list(eq);
        //循环判断
        assert receivers != null;
        //循环所有预约
        for (UseTimeEntity useTimeEntity : list) {
            DateTime kaishi = DateUtil.parse(useTimeEntity.getStartTime());
            DateTime jieshu = DateUtil.parse(useTimeEntity.getOverTime());
            if (start.after(kaishi) || start.before(jieshu) || over.after(kaishi) || over.before(jieshu)) {
                for (ReceiverInformation receiver : receivers) {
                    if (Objects.equals(receiver.getReceiverNumber(), useTimeEntity.getReceiverNumber())) {
                        receiver.setSure(0);
                    }
                }
            }
        }
        return ResponseRule.ok(receivers);
    }

    @Override
    public ResponseRule getAllFreePlatformByTime(String startTime, Integer keepTime) {
        //加载所有月台
        LambdaQueryWrapper<PlatformInformation> eq1 = platformService.getWrapper().eq(PlatformInformation::getPlatformIsUse, 0);
        List<PlatformInformation> Platforms = platformService.list(eq1);


        DateTime start = DateUtil.parse(startTime);
        DateTime over = start.offsetNew(DateField.MINUTE, keepTime);

        //取到当前小时内的所有预约  过滤到小时
        LambdaQueryWrapper<UseTimeEntity> eq = useTimeService.getWrapper()
                .eq(UseTimeEntity::getStartYear, "" + start.year())
                .eq(UseTimeEntity::getStartMonth, "" + (start.month() + 1))
                .eq(UseTimeEntity::getStartDay, "" + start.dayOfMonth());
//                .eq(UseTimeEntity::getStartHour, "" + (start.hour(true)));


        //当前小时内的所有预约单
        List<UseTimeEntity> list = useTimeService.list(eq);

        System.out.println("start ------->" + start);
        System.out.println("over ------->" + over);
        System.out.println("year ------->" + start.year());
        System.out.println("month ------->" + (start.month() + 1));
        System.out.println("day ------->" + start.dayOfMonth());
        System.out.println("hour ------->" + (start.hour(true)));
        System.out.println("length ------->" + list.size());

        //循环判断
        assert Platforms != null;
        //循环所有预约
        for (UseTimeEntity useTimeEntity : list) {
            DateTime kaishi = DateUtil.parse(useTimeEntity.getStartTime());
            DateTime jieshu = DateUtil.parse(useTimeEntity.getOverTime());


            System.out.println("kaishi ------->" + kaishi);
            System.out.println("jieshu ------->" + jieshu);

            if (start.after(kaishi) || start.before(jieshu) || over.after(kaishi) || over.before(jieshu)) {
                for (PlatformInformation platform : Platforms) {
                    if (Objects.equals(platform.getPlatformNumber(), useTimeEntity.getPlatformNumber())) {
                        platform.setSure(0);
                    }
                }
            }
        }
        return ResponseRule.ok(Platforms);
    }

    @Override
    public ResponseRule getBilOrder(String supplierNumber) {
        /**
         //增加订单选择功能
         uni.request({
         url: 'http://39.107.83.199:8045/api/EditGoodsClass/BilOrder',
         data: {
         "Suppliercode": uni.getStorageSync("userNumber")
         },
         method: 'POST',
         success(res) {
         console.log('订单数据', res)

         let ods = []

         for (let o of res.data) {
         requestUrl("reservation/supplier/getReservationByOrder", {
         orderNumber: o.orderno
         }, {
         method: "POST",
         header: {
         'content-type': 'application/x-www-form-urlencoded'
         }
         }, (res) => {
         if (res.data.code === 0) {
         ods.push(o)
         that.orders = ods
         }
         })

         }
         console.log(that.orders)
         // if(that.orders.length===0){
         // 	that.orders=[{orderno:"暂无可选订单"}]
         // }

         }
         })
         */
        List<Map> orders = new ArrayList<>();

        HttpResponse all = HttpRequest.post("http://39.107.83.199:8045/api/EditGoodsClass/BilOrder")
                .body("{Suppliercode:'" + supplierNumber + "'}")
                .header("Content-Type", "application/json;charset=UTF-8")
                .execute();
        JSONArray objects = JSONObject.parseArray(all.body());

        for (int i = 0; i <= objects.size() - 1; i++) {
            JSONObject jsonObject = objects.getJSONObject(i);
            String orderno = jsonObject.getString("orderno");
            LambdaQueryWrapper<OrderInformation> eq = orderMapper.getWrapper().eq(OrderInformation::getOrderNumber, orderno).eq(OrderInformation::getStatus, 0);
            List<OrderInformation> orderInformations = orderMapper.selectList(eq);
            if (ObjectUtil.isEmpty(orderInformations)) {
                HashMap<String, String> obj = new HashMap<>();
                obj.put("orderno", orderno);
                orders.add(obj);
            }
        }
        return ResponseRule.ok(orders);
    }

    private JSONArray getOrderInfo(String OrderNO) {
        HttpResponse all = HttpRequest.post("http://39.107.83.199:8045/api/EditGoodsClass/BilOrderInfo")
                .body("{OrderNO:'" + OrderNO + "'}")
                .header("Content-Type", "application/json;charset=UTF-8")
                .execute();
        return JSONObject.parseArray(all.body());
    }

    private String getBoxmount(List<Map> dtl) {
        HttpResponse all = HttpRequest.post("http://39.107.83.199:8045/api/EditGoodsClass/Boxamount")
                .body("{Dtl:" + JSONObject.toJSONString(dtl) + "}")
                .header("Content-Type", "application/json;charset=UTF-8")
                .execute();
        return all.body();
    }

    @Override
    public ResponseRule getBoxamount(String reservationNumber) {
        try {
            LambdaQueryWrapper<OrderInformation> eq = orderMapper.getWrapper().eq(OrderInformation::getReservationNumber, reservationNumber);
            List<OrderInformation> orderInformations = orderMapper.selectList(eq);
            Integer tuopanCount = 0;
            for (OrderInformation orderInformation : orderInformations) {
                HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
                HashMap<Object, Object> obj2 = new HashMap<>();
                ArrayList<Object> list = new ArrayList<>();
                objectObjectHashMap.put("OrderNO", orderInformation.getOrderNumber());

                HttpResponse all = HttpRequest.post("http://39.107.83.199:8045/api/EditGoodsClass/BilOrderInfo")
                        .body(JSONUtil.toJsonStr(objectObjectHashMap))
                        .header("Content-Type", "application/json;charset=UTF-8")
                        .execute();
                cn.hutool.json.JSONArray objects = JSONUtil.parseArray(all.body());

                for (int i = 0; i < objects.size(); i++) {
                    cn.hutool.json.JSONObject jsonObject = objects.getJSONObject(i);
                    HashMap<Object, Object> map = new HashMap<>();
                    map.put("Amount", jsonObject.getInt("amount"));
                    map.put("GoodsNO", jsonObject.getStr("gdscode"));
                    list.add(map);
                }
                obj2.put("Dtl", list);
                HttpResponse tuopans = HttpRequest.post("http://39.107.83.199:8045/api/EditGoodsClass/Boxamount")
                        .body(JSONUtil.toJsonStr(obj2))
                        .header("Content-Type", "application/json;charset=UTF-8")
                        .execute();
                tuopanCount += Integer.parseInt(tuopans.body());
            }
            return ResponseRule.ok(tuopanCount);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseRule.no("未知错误");
        }
    }

    @Override
    @webLog()
    public ResponseRule getUnReservationOrders(String supplierNumber) {
        List<Map> orders = new ArrayList<>();

        HttpResponse all = HttpRequest.post("http://39.107.83.199:8045/api/EditGoodsClass/BilOrder")
                .body("{Suppliercode:'" + supplierNumber + "'}")
                .header("Content-Type", "application/json;charset=UTF-8")
                .execute();
        JSONArray objects = JSONObject.parseArray(all.body());
        System.out.println(objects);
        for (int i = 0; i <= objects.size() - 1; i++) {
            JSONObject jsonObject = objects.getJSONObject(i);
            //得到订单号
            String orderno = jsonObject.getString("orderno");
            //查询有没有一样的订单号
            LambdaQueryWrapper<ReservationOrderInformation> eq1 = reservationOrderMapper.getWrapper().eq(ReservationOrderInformation::getOrderNumber, orderno);
            ReservationOrderInformation reservationOrderInformation = reservationOrderMapper.selectOne(eq1);
            if (ObjectUtil.isEmpty(reservationOrderInformation)) {
                JSONArray orderInfo = getOrderInfo(orderno);
//                List<Map> list = new ArrayList<>();
                Integer amounts = 0;
                for (int x = 0; x <= orderInfo.size() - 1; x++) {
                    JSONObject json = orderInfo.getJSONObject(x);
//                    String gdscode = json.getString("gdscode");
                    Integer amount = json.getInteger("amount");
                    amounts += amount;
//                    objectObjectHashMap.put("Amount",amount);
//                    objectObjectHashMap.put("GoodsNO",gdscode);
//                    list.add(objectObjectHashMap);
                }
                HashMap<String, Object> obj = new HashMap<>();
                obj.put("orderNo", orderno);
                obj.put("itemNum", orderInfo.size());
                obj.put("number", amounts);
                obj.put("recordDate", orderInfo.getJSONObject(0).getString("recordDate"));
                obj.put("endDate", orderInfo.getJSONObject(0).getString("enddate"));
                orders.add(obj);
            }
        }

        return ResponseRule.ok(orders);
    }

    @Override
    @webLog()
    public Map<String,Object> getUnReservationOrder(String orderNumber) {
        HashMap<String, Object> obj = new HashMap<>();
        LambdaQueryWrapper<ReservationOrderInformation> eq1 = reservationOrderMapper.getWrapper().eq(ReservationOrderInformation::getOrderNumber, orderNumber);
        ReservationOrderInformation reservationOrderInformation = reservationOrderMapper.selectOne(eq1);
        if (ObjectUtil.isEmpty(reservationOrderInformation)) {
            JSONArray orderInfo = getOrderInfo(orderNumber);
            Integer amounts = 0;
            for (int x = 0; x <= orderInfo.size() - 1; x++) {
                JSONObject json = orderInfo.getJSONObject(x);
                Integer amount = json.getInteger("amount");
                amounts += amount;
            }
            obj.put("orderNo", orderNumber);
            obj.put("itemNum", orderInfo.size());
            obj.put("number", amounts);
            obj.put("recordDate", orderInfo.getJSONObject(0).getString("recordDate"));
            obj.put("endDate", orderInfo.getJSONObject(0).getString("enddate"));
        } else {
            return null;
        }
        return obj;
    }


//    @Override
//    public ResponseRule getUnReservationOrders(String supplierNumber) {
//        List<Map> orders = new ArrayList<>();
//        LambdaQueryWrapper<SupplierOrderInformation> eq = supplierOrderMapper.getWrapper().eq(SupplierOrderInformation::getSupplierNumber, supplierNumber).eq(SupplierOrderInformation::getStatus, 0);
//        List<SupplierOrderInformation> supplierOrderInformations = supplierOrderMapper.selectList(eq);
//        if (ArrayUtil.isEmpty(supplierOrderInformations)) {
//            return ResponseRule.no("没有找到订单");
//        }
//        for (SupplierOrderInformation supplierOrderInformation : supplierOrderInformations) {
//            HashMap<String, String> obj = new HashMap<>();
//            obj.put("orderno", supplierOrderInformation.getOrderNumber());
//            orders.add(obj);
//        }
////        HttpResponse all = HttpRequest.post("http://39.107.83.199:8045/api/EditGoodsClass/BilOrder")
////                .body("{Suppliercode:'" + supplierNumber + "'}")
////                .header("Content-Type", "application/json;charset=UTF-8")
////                .execute();
////        JSONArray objects = JSONObject.parseArray(all.body());
////        for (int i = 0; i <= objects.size() - 1; i++) {
////            JSONObject jsonObject = objects.getJSONObject(i);
////            String orderno = jsonObject.getString("orderno");
////            LambdaQueryWrapper<OrderInformation> eq = orderMapper.getWrapper().eq(OrderInformation::getOrderNumber, orderno).eq(OrderInformation::getStatus,0);
////            List<OrderInformation> orderInformations = orderMapper.selectList(eq);
////            if (ObjectUtil.isEmpty(orderInformations)) {
////                HashMap<String, String> obj = new HashMap<>();
////                obj.put("orderno", orderno);
////                orders.add(obj);
////            }
////        }
//
//        return ResponseRule.ok(orders);
//    }


    //小程序二维码暂不能使用
    //原因：不是企业用户
    @Override
    public ResponseRule createReservationRetQRcode(String supplierNumber, String orderNumber) {
        ReservationInformation reservationInformation = new ReservationInformation();
        reservationInformation.setSupplierNumber(supplierNumber);
//        reservationInformation.set(orderNumber);
        ReservationInformation newReservation = this.addAndUp(reservationInformation);
        return null;
    }

//    @Override
//    public ResponseRule changePlatform(String reservationNumber,String platformNumber) {
//        ReservationInformation reservationInformation = reservationInformationMapper.selectOneById(reservationNumber);
//        reservationInformation.setActualPlatformNumber(platformNumber);
//        ReservationInformation re = this.addAndUp(reservationInformation);
//        return null;
//    }

}
